/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package smart_curriculum;


public class DataBase {
    
    public QQJDBCConnector() {
        url="jdbc:C:\\Users\\13603\\Documents\\Tencent Files\\1360368865\\FileRecv\\CustomerOrderSystem\\sqljdbc_4.1\\chs\\jre7=utf-8";
        user="root";
        pws="775823";
        conn=null;
    }   
    //建立连接
    public Connection getConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn=DriverManager.getConnection(url,user,pws);
        }catch (Exception e) {
            System.out.println("Error occurred obtaining connection");
            System.out.println(e.getMessage());
        }
        return conn;
    }
    
    url="jdbc:mysql://localhost/rQQ?useUnicode=true&characterEncoding=utf-8";
    
    
    public static String getUserName(String ID){
        String name = "";
            try{
                conn = new QQJDBCConnector().getConnection();
                stmt=conn.createStatement();
                sql="select user.name from user where user.name = '"+Sname+"'";
                rs=stmt.executeQuery(sql);
                while(rs.next()) {
                name=rs.getString("name");
            }
            stmt.close() ;
            conn.close() ;
            }catch (Exception e){
            System.out.println(e.getMessage());
        }
        return name;
    }
    
}

